package com.example.test;

import androidx.fragment.app.Fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import androidx.fragment.app.FragmentManager;

import java.util.ArrayList;

import java.util.List;

public class BlankFragment3 extends Fragment {



    public BlankFragment3() {
        // Required empty public constructor
    }
    private Context context;
    private List<String> mList = new ArrayList<>();


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_blank3, container, false);
        context = view.getContext();
        InitData();
        RecyclerView recyclerView = view.findViewById(R.id.recyclerview);
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(mList, new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                startActivity(new Intent(getContext(), MusicActivity.class));
            }
        });
//        定义布局规则
        LinearLayoutManager manager = new LinearLayoutManager(context);
//        垂直对齐
        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        为recyclerview添加布局规则
        recyclerView.setLayoutManager(manager);
        recyclerView.addItemDecoration(new DividerItemDecoration(context, LinearLayoutManager.VERTICAL));
        recyclerView.setAdapter(adapter);
        return view;

//        return inflater.inflate(R.layout.fragment_blank3, container, false);
    }

    private void InitData() {
        mList.add("把回忆拼好给你");
        mList.add("视频号");
        mList.add("直播");
        mList.add("扫一扫");
        mList.add("摇一摇");
        mList.add("看一看");
        mList.add("搜一搜");
        mList.add("附近");
        mList.add("购物");
        mList.add("游戏");
        mList.add("小程序");
    }
}